$(function () {
    var g = function (a, b) {
            var c = a.userPhoto.split("|").pop();
            return'<li class="' + (b ? "last" : "") + '"><a class="cmt-l-p" href="http://guang.com/u/' + a.userId + '"><img src="http://img.guang.com/' + c + '" width="20" height="20"/></a><div class="cmt-l-c wbbw"><a href="http://guang.com/u/' + a.userId + '">' + a.userNick + "</a><span>: " + a.content + '</span><span class="cmt-l-t ml10">' + a.showTime + '</span></div><span class="cmt-l-b"><a rel="feedsreply" data-name="' + a.userNick + '" data-id="' + a.feedsId + '" href="javascript:;">\u56de\u590d</a></span></li>'
        },
        i = function (a, b) {
            var c = "feedsCmtPagination_" + a;
            $("#itemCmt_" + a).append('<div class="clearfix pt10"><div id="' + c + '" class="pagin fr pagination"></div></div>');
            $("#" + c).pagination(b, {num_edge_entries:2, num_display_entries:4, callback:function (b) {
                h(b + 1, a);
                return!1
            }, items_per_page:10, callback_run:!1, current_page:0})
        }, h = function (a, b) {
            $.ajax({url:GUANGER.path + "/showFeedsReplies", type:"post", dataType:"json", data:{feedsId:b, pageNo:a}, success:function (a) {
                if (100 == a.code) {
                    var d;
                    d = a.feedsReplyList;
                    if (d[0]) {
                        for (var f =
                            "<ul>", e = 0; e < d.length; e++)f = e == d.length - 1 ? f + g(d[e], "last") : f + g(d[e]);
                        d = f + "</ul>"
                    } else d = "<ul></ul>";
                    $("#itemCmt_" + b + " .cmt-list").html(d);
                    10 < parseInt(a.repliesCount, 10) && !$("#feedsCmtPagination_" + b).children().length && i(b, parseInt(a.repliesCount, 10))
                } else 110 == a.code && $("#itemCmt_" + b + " .cmt-list").html("<ul></ul>")
            }})
        }, j = function (a, b) {
            return/^\s*$/.test(b) ? ($.guang.tip.conf.tipClass = "tipmodal tipmodal-error", $.guang.tip.show(a, "\u56de\u590d\u5185\u5bb9\u4e0d\u80fd\u4e3a\u7a7a~"), !1) : 1E3 < $.guang.util.getStrLength(b) ?
                ($.guang.tip.conf.tipClass = "tipmodal tipmodal-error", $.guang.tip.show(a, "\u56de\u590d\u5185\u5bb9\u4e0d\u80fd\u8d85\u8fc71000~"), !1) : !0
        }, k = function (a) {
            var b = a.data("id"), c = $("#itemCmt_" + b).find("textarea").val();
            j(a, c) && $.ajax({url:GUANGER.path + "/feedsReply", type:"post", dataType:"json", data:{feedsId:b, content:c}, success:function (a) {
                100 == a.code && ($("#itemCmt_" + b).find("textarea").val(""), a = g(a.feedsReply), $("#itemCmt_" + b + " .cmt-list ul").prepend(a))
            }})
        };
    $("a[rel=feedscmt]").live("click", function () {
        if ($.guang.dialog.isLogin()) {
            var a =
                $(this).attr("data-id"), b = $(this), c = "itemCmt_" + a;
            $("#" + c).length ? $("#" + c).remove() : (c = '<div id="' + c + '" class="item-cmt">' + ('<div class="cmt-form"><div class="cmt-i"><textarea class="b-textarea"></textarea></div><div class="cmt-s clearfix"><a href="javascript:;" class="sbl-btn fr J_cmtSubmit" data-id="' + a + '">\u8bc4\u8bba</a></div></div>') + '<div class="cmt-list"></div></div>', b.parents(".item").append(c), b.parents(".feeds-info").after(c), h(1, a))
        }
    });
    $("a[rel=feedsreply]").live("click", function () {
        if ($.guang.dialog.isLogin()) {
            var a =
                $(this);
            a.parents(".item-cmt").find("textarea").val("@" + a.data("name") + ":")
        }
    });
    $(".J_cmtSubmit").live("click", function () {
        $.guang.dialog.isLogin() && k($(this))
    })
});
